/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.rvalerio.foregroundappchecker;

import com.rvalerio.fgchecker.AppChecker;
import com.rvalerio.fgchecker.detectors.Detector;
import com.rvalerio.fgchecker.detectors.LollipopDetector;
import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.eventhandler.EventHandler;
import ohos.eventhandler.EventRunner;
import org.junit.Test;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;

public class AppCheckerTest {

    private AppChecker appChecker;
    private Detector detector;
    private ScheduledExecutorService service;
    private EventHandler handler;

    @Test
    public void testBundleName() {
        final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName();
        assertEquals("com.rvalerio.foregroundappchecker", actualBundleName);
    }

    @Test
    public void setup() {
        appChecker = new AppChecker();
    }

    @Test
    public void shouldGetTimeOut() {
        appChecker.setTimeOut(1000);
        assertTrue(appChecker.getTimeOut() == 1000);
    }

    @Test
    public void detectorNotNullTest() {
        detector = new LollipopDetector();
        assertNotNull(detector);
    }

    @Test
    public void serviceNotNullTest() {
        service = new ScheduledThreadPoolExecutor(1);
        assertNotNull(service);
    }

    @Test
    public void handlerNotNullTest() {
        EventRunner eventRunner = EventRunner.getMainEventRunner();
        handler = new EventHandler(eventRunner);
        assertNotNull(handler);
    }
}